package demo9;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;

public class test6 {
    public static void main(String[] args) {
        //获取当前时间的日历对象（包或 年月日）
        LocalDate nowDate = LocalDate.now();
        //System.out.println("今天的日期："+nowDate);

        //获取指定时间的日历对象
        LocalDate idDate = LocalDate.of(2023,1,1);
        System.out.println("指定日期："+idDate);

        System.out.println("===========================");
        //3，get系列方法获取日历的每一个属性值
        //获取年
        int year = idDate.getYear();
        System.out.println("year："+year);
        System.out.println("===========================");
        //获取月
        //方式1：
        Month m = idDate.getMonth();
        System.out.println(m);
        System.out.println(m.getValue());

        //方式2
        int month = idDate.getMonthValue();
        System.out.println("month："+month);
        System.out.println("===========================");

        //获取日(一个月中的第几天)
        int day1 = idDate.getDayOfMonth();
        System.out.println("day:"+day1);

        //获取一年的第几天
        int day2 = idDate.getDayOfYear();
        System.out.println("dayOfYear:"+day2);

        //获取星期(中的第几天)
        DayOfWeek dayOfWeek =idDate.getDayOfWeek();
        System.out.println("week:"+dayOfWeek);
        System.out.println(dayOfWeek.getValue());
        System.out.println("===========================");

        //is开头的方法表示判断
        System.out.println(idDate.isBefore(idDate));
        System.out.println(idDate.isAfter(idDate));

        //with开头的方法表示修改，只能修改年月日
        LocalDate withLocalDate = idDate.withYear(2000);
        System.out.println(withLocalDate);
        System.out.println(withLocalDate == idDate);
        System.out.println("===========================");

        //minus开头的方法表示减少，只能减少年月日
        LocalDate minusLocalDate = idDate.minusYears(1);
        System.out.println(minusLocalDate);
        System.out.println("===========================");

        //plus开头的方法表示增加，只能增加年月日
        LocalDate plusLocalDate = idDate.plusDays(1);
        System.out.println(plusLocalDate);
        System.out.println("===========================");

        //判断今天是否是你的生日
        LocalDate birDate = LocalDate.of(2003,4,30);
        LocalDate nowDate1 = LocalDate.now();
        MonthDay birMd = MonthDay.of(birDate.getMonthValue(),birDate.getDayOfMonth());
        MonthDay nowMd = MonthDay.from(nowDate1);
        System.out.println("今天是你的生日吗？"+birMd.equals(nowMd));//今天是你的生日吗？
    }
}
